package com.example.administrator.shzs.activity;

import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.example.administrator.shzs.R;
import com.example.administrator.shzs.app.MyApplication;
import com.example.administrator.shzs.receiver.ConnectionChangeReceiver;

/**
 * 所有Activity父类
 */
public class BaseActivity extends FragmentActivity {

    ConnectionChangeReceiver myReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);
        MyApplication.app.activityList.add(this);

        registerReceiver();

    }



    /**
     * 注册监听器
     */
    private void registerReceiver(){
        IntentFilter filter=new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        myReceiver=new ConnectionChangeReceiver(this);
        this.registerReceiver(myReceiver, filter);
    }


    /**
     * 取消监听
     */
    private void unregisterReceiver(){
        this.unregisterReceiver(myReceiver);
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver();
        MyApplication.app.activityList.remove(this);
    }
}
